<template>
  <div id="setup">
    <h3>
      <van-icon
        name="arrow-left"
        color="rgb(107, 107, 107)"
        @click="routerGoBack"
      />

      <span>设置</span>
    </h3>
    <div class="lists">
      <div class="item" v-for="(item, i) in textList" :key="i">
        <h5 v-if="i == 3">隐私</h5>
        <p
          v-for="(it, j) in item.text"
          :key="j"
          :class="{ 'text-center': i == 7 || i == 6 }"
          @click="moreClickEvent"
        >
          <span>{{ it }}</span>
          <span v-if="!(i == 7 || i == 6)">
            <van-icon name="arrow" color="rgb(107, 107, 107)" />
          </span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import WebIM from "../../utils/WebIM";
export default {
  name: "setUp",
  data() {
    return {
      textList: [
        { text: ["账号与安全"] },
        { text: ["青少年模式", "关怀模式"] },
        { text: ["新消息通知", "聊天", "通用"] },
        { text: ["朋友权限", "个人信息与权限", "个人信息收集清单"] },
        { text: ["关于微信", "帮助与反馈"] },
        { text: ["插件"] },
        { text: ["切换账号"] },
        { text: ["退出"] },
      ],
    };
  },
  methods: {
    routerGoBack() {
      this.$router.go(-1);
    },
    moreClickEvent(evt) {
      // 退出登录
      if (evt.target.innerText == "退出") {
        // 1 代表退出后跳转至initpage页面
        this.logOut(1);
      } else if (evt.target.innerText == "切换账号") {
        // 2 代表跳到SwitchToUserPage页面
        this.logOut(2);
      }
    },
    logOut(num) {
      if (num == 1) {
        WebIM.conn.close();
        this.$store.commit("setIsLogin", false);
        // 清除tonken
        this.$cookies.remove("wxUserToken");
        sessionStorage.removeItem("wxUserInfo");
        this.$router.push({
          path: "/init",
        });
      } else {
        this.$router.push({
          name: "switchToUser",
          params: {
            imgurl: this.$route.params.imgurl,
            userNickName: this.$route.params.userNickName,
            userPhone: this.$route.params.userPhone,
          },
        });
      }
    },
  },
};
</script>

<style lang="scss">
#setup {
  width: 100vw;
  color: #fff;
  background-color: var(--theme-background-black);
  h3 {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
    padding: 10px;
    span {
      flex: 1;
      text-align: center;
      margin-right: 28px;
      width: 100%;
      color: #eee;
    }
  }
  .lists {
    .item {
      background-color: var(--theme-cell-black);
      &:not(:last-child) {
        margin-bottom: 10px;
      }
      h5 {
        padding: 10px;
        font-size: 13px;
        background-color: var(--theme-background-black);
      }
      p {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0 10px;
        width: 100%;
        height: 45px;
        line-height: 45px;
        &:not(:last-child) {
          border-bottom: 1px solid rgb(47 42 42);
        }
      }
      .text-center {
        span {
          flex: 1;
          text-align: center;
        }
      }
    }
  }
}
</style>